package com.chuyu.jzwboa.adapter.offmoblie;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chuyu.jzwboa.R;

import java.util.List;

/**
 * @author 杨仕俊
 * @description 公文管理中xrecycleview的adapter
 * Created by wo on 2017/12/16.
 */

public class OffDocFragAdapter extends RecyclerView.Adapter<OffDocFragAdapter.ViewHodlerDoc> {
    private Context context;
    private List<String> list;

    public OffDocFragAdapter(Context context, List<String> list, OnItemClickListeners onitemclicklistner) {
        this.context = context;
        this.list = list;
        this.onitemclicklistner = onitemclicklistner;
    }


    @Override
    public ViewHodlerDoc onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_off_doc, parent, false);
        return new ViewHodlerDoc(view);
    }

    @Override
    public void onBindViewHolder(ViewHodlerDoc holder, final int position) {
        if (onitemclicklistner != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onitemclicklistner.onItemclick(view, position);
                }
            });
        }
        if (position==list.size()-1){
            holder.lineView.setVisibility(View.INVISIBLE);
        }
    }


    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class ViewHodlerDoc extends RecyclerView.ViewHolder {

        public ImageView ivOffDoc;
        public ImageView ivRed;
        public TextView offTitle;
        public TextView offTime;
        public TextView offName;
        public View lineView;
        public ViewHodlerDoc(View itemView) {
            super(itemView);
            ivOffDoc = itemView.findViewById(R.id.iv_offdoc);
            ivRed = itemView.findViewById(R.id.iv_offdoc_red);
            offTitle = itemView.findViewById(R.id.text_offdoc_title);
            offTime = itemView.findViewById(R.id.text_offdoc_time);
            offName = itemView.findViewById(R.id.text_offdoc_name);
            lineView=itemView.findViewById(R.id.line_view);
        }
    }

    /**
     * 定义一个接口  接口回调
     */
    public interface OnItemClickListeners {
        void onItemclick(View view, int position);

    }

    private OnItemClickListeners onitemclicklistner;

    public void setOnItemClickListener(OnItemClickListeners onitemclick) {
        this.onitemclicklistner = onitemclick;
    }
}
